import request from '../../../utils/request.js'
import { exportFile } from '../../exportFile.js'
const prefix1 = process.env.VUE_APP_BASE_API9 // sku
const prefix2 = process.env.VUE_APP_BASE_API8 // process
const prefix3 = process.env.VUE_APP_BASE_API7 // config
const prefix4 = process.env.VUE_APP_BASE_API6 // item-coi-buyer-agent
// const prefix5 = process.env.VUE_APP_BASE_API11
// 审核
const url = {
  findSkuBuildInfoBySkuId: `${prefix1}/online/design/findSkuBuildInfoBySkuId`, // 获取制品信息
  purchaseApprovalList: `${prefix2}/purchaseReviewController/findPage`, // 采购列表
  purchaseApproved: `${prefix2}/purchaseReviewController/buyerApproved`, // 采购同意
  purchaseReject: `${prefix2}/purchaseReviewController/buyerReject`, // 拒绝
  complianceApprovalList: `${prefix2}/complianceAuditController/findPage`, // 合规列表
  complianceApproved: `${prefix2}/complianceAuditController/complianceApproved`, // 合规同意
  complianceReject: `${prefix2}/complianceAuditController/complianceReject`, // 合规拒绝
  processData: `${prefix2}/purchaseReviewController/processData`, // 日志
  reasonController: `${prefix3}/reasonController/selectPage`, // 驳回原因
  complianceExport: `${prefix2}/complianceAuditController/complianceExport`, // 合规审核导出
  purchaseReviewExport: `${prefix2}/purchaseReviewController/purchaseReviewExport` // 采购审核导出
}
//  建品任务
const url_schedule = {
  allTasks: `${prefix1}/skuInfo/findBuyerBuildSkuPage`, // 所有建品
  processingTasks: `${prefix1}/skuInfo/findBuyerBuildSkuTaskPage`, // 待我处理
  historicalTasks: `${prefix1}/history-build/query/page`, // 历史建品
  allTasksExport: `${prefix1}/skuInfo/exportBuyerBuildSku`, // 所有建品导出
  abandonedTask: `${prefix1}/skuInfo/cancellation`, // 废弃线上建品任
  sign: `${prefix1}/buyer-build/sku/marking`, // 打标商品类型
  newItemList: `${prefix1}/build/query/page`, // 线上未建品清单
  initiateTask: `${prefix1}/build/create/onlineBuild`, // 发起线上建品
  chooseStandard: `${prefix1}/buyer-build/save/buildStandard`, // 建品标准
  getSupplier: `${prefix3}/content-vendor/queryAllCVendorList`, // 获取供应商合作的文描商
  getPbSupplier: `${prefix1}/content-vendor/search-content`, // 部门fin查相应的pb文描供应商
  exportComplianceAuditSkuProcess: `${prefix1}/chg-sku/exportComplianceAuditSkuProcess` // 导出接口
}
// 制品
const url_products = {
  creationWay: `${prefix1}/buyer-build/save/creationWay`, // 提交建品方式
  building: `${prefix1}/online/building`, // 补充委托信息-聚合接口
  saveBuilding: `${prefix1}/buyer-build/save/entrustInfo`, // 保存补充委托信息
  submit: `${prefix1}/buyer-build/submit/entrustInfo`, // 提交委托信息
  queryTreeList: `${prefix4}/category/queryTreeList`, // 店铺类目optiaons
  queryChannelTreeList: `${prefix4}/category/queryChannelTreeList`, // 平台类目options
  uploadSkuOptionalResource: `${prefix1}/online/design/uploadSkuOptionalResource`, // 上传商品素材
  deleteSkuOptionalResource: `${prefix1}/online/design/deleteSkuOptionalResource`, // 删除商品素材素材
  uploadSkuContentResource: `${prefix1}/online/design/uploadSkuContentResource`, // 上传文描图片
  deleteSkuContentResource: `${prefix1}/online/design/deleteSkuContentResource`, // 删除文描图片
  uploadFile: `${prefix1}/file/upload`, // 上传付款凭据
  delFile: `${prefix1}/file/delete`, // 删除付款凭据
  exportExcel: `${prefix1}/online/building/selling/exportExcel`, // 下载卖点文件
  uploadExcel: `${prefix1}/online/building/selling/importExcel` // 上传卖点文件
}

// 制作页面
const url_making = {
  getCategory: `${prefix1}/category/search-category`, // 类目接口
  saveCategory: `${prefix1}/category/save`, // 类目保存
  categoryCheck: `${prefix1}/online/building/category/check`,
  uploadSkuResource: `${prefix1}/online/design/uploadSkuResource`, // 商品图片
  deleteSkuResource: `${prefix1}/online/design/deleteSkuResource`, //
  goodsInfosava: `${prefix1}/online/design/save`,
  batchSubmitApproval: `${prefix1}/buyer-making/submit`,
  jdArea: `${prefix1}/category/jd-area`,
  refresh: `${prefix1}/skuInfo/reload/yjdf`
}

// 线上商品库
const list_url = {
  commoditylibraryExport: `${prefix1}/chg-sku/findChgSkuBaseInfoPage`,
  commoditylibraryExports: `${prefix1}/chg-sku/chgSkuBaseInfoExcel`,
  commoditylibraryList: `${prefix1}/chg-sku/findChgSkuBaseInfoPage`,
  commoditylibraryBatchEdit: `${prefix1}/chg-sku/findChgSkuBaseInfoPage`,
  findAndSaveSkuInfoByUpcNbr: `${prefix1}/chg-sku/findAndSaveSkuInfoByUpcNbr`,
  commodityDetail: `${prefix1}/chg-sku/findSkuChannelInfoByUpcNbr`,
  commodityInfoSave: `${prefix1}/chg-sku/saveSkuInfo`,
  maintainList: `${prefix1}/chg-sku/findChgSkuInfoTaskPage`,
  deleteSkuChannelResource: `${prefix1}/chg-sku/deleteSkuChannelResource`,
  deleteSkuContentResource2: `${prefix1}/chg-sku/deleteSkuContentResource`,
  uploadSkuChannelResource: `${prefix1}/chg-sku/uploadSkuChannelResource`,
  uploadSkuContentResource2: `${prefix1}/chg-sku/uploadSkuContentResource`,
  findChgSkuInfoByProcessId: `${prefix1}/chg-sku/findChgSkuInfoByProcessId`,
  submitApproval: `${prefix1}/chg-sku/submitApproval`,
  revocation: `${prefix1}/chg-sku/revocation`,
  cancellation: `${prefix1}/chg-sku/cancellation`,
  pushSkuInfo: `${prefix1}/chg-sku/pushSkuInfo`,
  operationLogByUpcNbr: `${prefix1}/chg-sku/findSkuOperationLogByUpcNbr`, // 渠道商品库操作日志
  operationLogByProcessId: `${prefix1}/chg-sku/getChgShuProcessLogListFindByProcessId`, // 商品维护任务操作日志
  saveAndPushSkuInfo: `${prefix1}/chg-sku/saveAndPushSkuInfo`,
  findChannelInfos: `${prefix1}/chg-sku/findChannelInfos`,
  findBuyerAuditSkuProcessPage: `${prefix1}/chg-sku/findBuyerAuditSkuProcessPage`,
  procurementApproval: `${prefix1}/chg-sku/procurementApproval`,
  rejectedApproval: `${prefix1}/chg-sku/rejectedApproval`,
  findComplianceAuditSkuProcessPage: `${prefix1}/chg-sku/findComplianceAuditSkuProcessPage`,
  complianceApproval: `${prefix1}/chg-sku/complianceApproval`,
  throughApproval: `${prefix1}/chg-sku/throughApproval`,
  findChgSkuChannelPage: `${prefix1}/chg-sku/findChgSkuChannelPage`,
  findSkuChannelInfoByChannel: `${prefix1}/chg-sku/findSkuChannelInfoByChannel`,
  findAndSaveSkuChannelInfoByChannel: `${prefix1}/chg-sku/findAndSaveSkuChannelInfoByChannel`,
  rejectedProcurementApproval: `${prefix1}/chg-sku/rejectedProcurementApproval`,
  rejectedComplianceApproval: `${prefix1}/chg-sku/rejectedComplianceApproval`,
  throughComplianceApproval: `${prefix1}/chg-sku/throughComplianceApproval`,
  throughProcurementApproval: `${prefix1}/chg-sku/throughProcurementApproval`,
  batchUpdateSkuShopCatByChannel: `${prefix1}/chg-sku/batchUpdateSkuShopCatByChannel`,
  batchUpdateSkuAllChannel: `${prefix1}/chg-sku/batchUpdateSkuAllChannel`,
  skuRepublishByChannel: `${prefix1}/chg-sku/skuRepublishByChannel`,
  querySkuByChannel: `${prefix1}/chg-sku/querySkuByChannel`
  // pageSpuChannelInfo: `${prefix5}/spu/spuInfo/aloha/pageSpuChannelInfo`  skuInfo/aloha/sku/querySkuByChannel
}
/**
 * 线上建品审核
 */

// 获取制品信息
export const findSkuBuildInfoBySkuId = (id, formRoute) => {
  let urlPath = `${url.findSkuBuildInfoBySkuId}/${id}`
  if (formRoute === 'examine') urlPath = `${prefix1}/sku/unshelf/detail/${id}`
  return request({
    url: urlPath
  })
}

// 获取列表
export const purchaseApprovalList = (data) => {
  return request({
    method: 'post',
    url: url.purchaseApprovalList,
    data
  })
}

// 采购同意
export const purchaseApproved = (data) => {
  return request({
    method: 'post',
    url: url.purchaseApproved,
    data
  })
}

// 采购拒绝
export const purchaseReject = (data) => {
  return request({
    method: 'post',
    url: url.purchaseReject,
    data
  })
}

// 获取列表
export const complianceApprovalList = (data) => {
  return request({
    method: 'post',
    url: url.complianceApprovalList,
    data
  })
}

// 采购同意
export const complianceApproved = (data) => {
  return request({
    method: 'post',
    url: url.complianceApproved,
    data
  })
}

// 采购拒绝
export const complianceReject = (data) => {
  return request({
    method: 'post',
    url: url.complianceReject,
    data
  })
}

// 查看操作日志
export const processData = (data) => {
  return request({
    method: 'post',
    url: url.processData,
    data
  })
}

// 驳回原因
export const reasonController = (data) => {
  return request({
    method: 'post',
    url: url.reasonController,
    data
  })
}

// 合规导出
export const complianceExport = (data, name) => {
  return exportFile(url.complianceExport, data, name)
}

// 采购导出
export const purchaseReviewExport = (data, name) => {
  return exportFile(url.purchaseReviewExport, data, name)
}

/**
 * 线上建品
 */

// 所有任务列表
export const allTasks = (data) => {
  return request({
    method: 'post',
    url: url_schedule.allTasks,
    data
  })
}

// 待我处理任务列表
export const processingTasks = (data) => {
  return request({
    method: 'post',
    url: url_schedule.processingTasks,
    data
  })
}

// 历史建品任务列表
export const historicalTasks = (data) => {
  return request({
    method: 'post',
    url: url_schedule.historicalTasks,
    data
  })
}

// 所有任务列表导出
export const allTasksExport = (data, name) => {
  return exportFile(url_schedule.allTasksExport, data, name)
}

// 待我处理任务列表导出
export const processingTasksExport = (data, name) => {
  return exportFile(url_schedule.processingTasksExport, data, name)
}

// 历史建品任务列表导出
export const historicalTasksExport = (data, name) => {
  return exportFile(url_schedule.historicalTasksExport, data, name)
}

// 作废线上建品
export const abandonedTask = (data) => {
  return request({
    method: 'post',
    url: url_schedule.abandonedTask,
    data
  })
}

// 打标商品类型
export const sign = (data) => {
  return request({
    method: 'post',
    url: url_schedule.sign,
    data
  })
}

// 发起线上建品列表清单
export const newItemList = (data) => {
  return request({
    method: 'post',
    url: url_schedule.newItemList,
    data
  })
}

// 发起线上建品
export const initiateTask = (data) => {
  return request({
    method: 'post',
    url: url_schedule.initiateTask,
    data
  })
}

// 选择线上建品标准
export const chooseStandard = (data) => {
  return request({
    method: 'post',
    url: url_schedule.chooseStandard,
    data
  })
}

export const getSupplier = () => {
  return request({
    url: url_schedule.getSupplier
  })
}

// 获取Pb文描服务商
export const getPbSupplier = (data) => {
  return request({
    method: 'post',
    url: url_schedule.getPbSupplier,
    data
  })
}

/**
 * 制品
 */

// 提交建品方式
export const creationWay = (data) => {
  return request({
    method: 'post',
    url: url_products.creationWay,
    data
  })
}

// 上传SKU素材图片资源文件
export const uploadSkuOptionalResource = (data) => {
  return request({
    method: 'put',
    url: url_products.uploadSkuOptionalResource,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 删除SKU素材图片资源文件
export const deleteSkuOptionalResource = (data) => {
  return request({
    method: 'post',
    url: url_products.deleteSkuOptionalResource,
    data
  })
}

// 上传SKU文描图片资源文件
export const uploadSkuContentResource = (data) => {
  return request({
    method: 'put',
    url: url_products.uploadSkuContentResource,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 删除SKU文描图片资源文件
export const deleteSkuContentResource = (data) => {
  return request({
    method: 'post',
    url: url_products.deleteSkuContentResource,
    data
  })
}

// 上传凭证
export const uploadFile = (data) => {
  return request({
    method: 'put',
    url: url_products.uploadFile,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 删除凭证
export const delFile = (data) => {
  return request({
    method: 'post',
    url: url_products.delFile,
    data
  })
}

// 下载卖点表格
export const exportExcel = (data, name) => {
  return exportFile(url_products.exportExcel, data, name)
}

// 上传SKU文描图片资源文件
export const uploadExcel = (data) => {
  return request({
    method: 'put',
    url: url_products.uploadExcel,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 获取委托信息
export const building = (params) => {
  return request({
    method: 'get',
    url: url_products.building,
    params
  })
}

// 保存委托信息
export const saveBuilding = (data) => {
  return request({
    method: 'post',
    url: url_products.saveBuilding,
    data
  })
}

// 获取店铺类目options(已做处理 ,只需要传入channelId)
export const queryTreeList = (data) => {
  return request({
    method: 'post',
    url: url_products.queryTreeList,
    data: {
      ...data,
      shopCategoryFlag: 1
    }
  })
}

// 获取平台类目options(已做处理 ,只需要传入channelId)
export const queryChannelTreeList = (data) => {
  return request({
    method: 'post',
    url: url_products.queryChannelTreeList,
    data: {
      ...data,
      shopCategoryFlag: 0
    }
  })
}

// 提交委托
export const submit = (data) => {
  return request({
    method: 'post',
    url: url_products.submit,
    data
  })
}

export const getCategory = (params) => {
  return request({
    method: 'get',
    url: url_making.getCategory,
    params
  })
}
export const saveCategory = (data) => {
  return request({
    method: 'post',
    url: url_making.saveCategory,
    data
  })
}

// 检查是否维护完渠道类目信息
export const categoryCheck = (params) => {
  return request({
    method: 'get',
    url: url_making.categoryCheck,
    params
  })
}
// 上传SKU图片资源文件(商品主图)
export const uploadSkuResource = (data) => {
  return request({
    method: 'put',
    url: url_making.uploadSkuResource,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}
// 删除SKU图片资源文件
export const deleteSkuResource = (data) => {
  return request({
    method: 'post',
    url: url_making.deleteSkuResource,
    data
  })
}
// 保存制品
export const goodsInfosava = (data) => {
  return request({
    method: 'post',
    url: url_making.goodsInfosava,
    data
  })
}

// 批量提交审核
export const batchSubmitApproval = (data) => {
  return request({
    method: 'post',
    url: url_making.batchSubmitApproval,
    data
  })
}

// 线上商品库
export const commoditylibraryList = (params) => {
  return request({
    method: 'post',
    url: list_url.commoditylibraryList,
    data: params
  })
}

// 线上商品库批量编辑
export const commoditylibraryBatchEdit = (params) => {
  return request({
    method: 'post',
    url: list_url.commoditylibraryBatchEdit,
    data: params
  })
}

// 线上商品库导出
export const commoditylibraryExport = (data, name) => {
  return exportFile(list_url.commoditylibraryExport, data, name)
}

// 获取线上商品信息
export const findAndSaveSkuInfoByUpcNbr = (id) => {
  return request({
    url: list_url.findAndSaveSkuInfoByUpcNbr + '/' + id
  })
}

// 获取线上商品详情
export const commodityDetail = (id) => {
  return request({
    url: list_url.commodityDetail + '/' + id
  })
}

// 线上商品信息修改
export const commodityInfoSave = (params) => {
  return request({
    method: 'post',
    url: list_url.commodityInfoSave,
    data: params
  })
}
// 线上商品维护列表
export const maintainList = (params) => {
  return request({
    method: 'post',
    url: list_url.maintainList,
    data: params
  })
}

// 上传SKU素材图片资源文件
export const uploadSkuChannelResource = (data) => {
  return request({
    method: 'put',
    url: list_url.uploadSkuChannelResource,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}
// 删除SKU素材图片资源文件
export const deleteSkuChannelResource = (data) => {
  return request({
    method: 'post',
    url: list_url.deleteSkuChannelResource,
    data
  })
}

// 上传SKU文描图片资源文件
export const uploadSkuContentResource2 = (data) => {
  return request({
    method: 'put',
    url: list_url.uploadSkuContentResource2,
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 删除SKU文描图片资源文件
export const deleteSkuContentResource2 = (data) => {
  return request({
    method: 'post',
    url: list_url.deleteSkuContentResource2,
    data
  })
}

// 根据id查询sku维护信息
export const findChgSkuInfoByProcessId = (id) => {
  return request({
    url: list_url.findChgSkuInfoByProcessId + '/' + id
  })
}

// 提交审核
export const submitApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.submitApproval,
    data: params
  })
}

// 撤回
export const revocation = (params) => {
  return request({
    method: 'post',
    url: list_url.revocation,
    data: params
  })
}

// 作废
export const cancellation = (params) => {
  return request({
    method: 'post',
    url: list_url.cancellation,
    data: params
  })
}

// 更新到渠道
export const pushSkuInfo = (processId) => {
  return request({
    url: list_url.pushSkuInfo + '/' + processId
  })
}

// 渠道商品库操作日志
export const operationLogByUpcNbr = (params) => {
  return request({
    method: 'post',
    url: list_url.operationLogByUpcNbr,
    data: params
  })
}

// 保存&推送sku信息
export const saveAndPushSkuInfo = (params) => {
  return request({
    method: 'post',
    url: list_url.saveAndPushSkuInfo,
    data: params
  })
}

// 商品维护任务操作日志
export const operationLogByProcessId = (upcNbr) => {
  return request({
    url: list_url.operationLogByProcessId + '/' + upcNbr
  })
}

// 获取渠道下拉
export const findChannelInfos = (params) => {
  return request({
    method: 'get',
    url: list_url.findChannelInfos,
    params
  })
}

// 品类运营初审（维护）
export const findBuyerAuditSkuProcessPage = (params) => {
  return request({
    method: 'post',
    url: list_url.findBuyerAuditSkuProcessPage,
    data: params
  })
}

// 品类运营初审（维护）的审核
export const procurementApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.procurementApproval,
    data: params
  })
}

// 品类运营初审（维护）的驳回
export const rejectedApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.rejectedApproval,
    data: params
  })
}

// GBS终审（维护）
export const findComplianceAuditSkuProcessPage = (params) => {
  return request({
    method: 'post',
    url: list_url.findComplianceAuditSkuProcessPage,
    data: params
  })
}

// GBS终审（维护）审核
export const complianceApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.complianceApproval,
    data: params
  })
}

// 审核通过
export const throughApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.throughApproval,
    data: params
  })
}

// 商品渠道库信息
export const findChgSkuChannelPage = (params, menuName) => {
  const url = list_url.findChgSkuChannelPage
  const data = params
  // if (menuName === 'JDWX') {
  //   url = list_url.querySkuByChannel
  //   data.upcWoCdList = data.skuList
  //   // data.channelId = '12'
  //   delete data.skuList
  // }
  return request({
    method: 'post',
    url,
    data
  })
}

// 渠道商品详情
export const findSkuChannelInfoByChannel = (params) => {
  return request({
    method: 'post',
    url: list_url.findSkuChannelInfoByChannel,
    data: params
  })
}

// 渠道商品编辑详情
export const findAndSaveSkuChannelInfoByChannel = (params) => {
  return request({
    method: 'post',
    url: list_url.findAndSaveSkuChannelInfoByChannel,
    data: params
  })
}

// 品类运营驳回
export const rejectedProcurementApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.rejectedProcurementApproval,
    data: params
  })
}

// GBS审核驳回
export const rejectedComplianceApproval = (params) => {
  return request({
    method: 'post',
    url: list_url.rejectedComplianceApproval,
    data: params
  })
}

// 通过GBS审核
export const throughComplianceApproval = (processId) => {
  return request({
    method: 'get',
    url: list_url.throughComplianceApproval + '/' + processId
  })
}

// 通过品类运营审核
export const throughProcurementApproval = (processId) => {
  return request({
    method: 'get',
    url: list_url.throughProcurementApproval + '/' + processId
  })
}

// 获取京东地区级联
export const jdArea = (data) => {
  return request({
    method: 'post',
    url: url_making.jdArea,
    data
  })
}

export const refresh = (params) => {
  return request({
    method: 'get',
    url: `${url_making.refresh}/${params}`
  })
}

// sku单渠道批量编辑
export const batchUpdateSkuShopCatByChannel = (params) => {
  return request({
    method: 'post',
    url: list_url.batchUpdateSkuShopCatByChannel,
    data: params
  })
}

// sku全渠道批量编辑
export const batchUpdateSkuAllChannel = (params) => {
  return request({
    method: 'post',
    url: list_url.batchUpdateSkuAllChannel,
    data: params
  })
}

// sku单渠道批量更新渠道
export const skuRepublishByChannel = (params) => {
  return request({
    method: 'post',
    url: list_url.skuRepublishByChannel,
    data: params
  })
}

// 委托
export const skuEntrustModify = (params) => {
  return request({
    method: 'post',
    url: `${prefix1}/chg-sku-delegate/authorize/whichToUpdate`,
    data: params
  })
}

// 查询供应商名称
export const skuSupplierName = (data) => {
  return request({
    method: 'post',
    url: `${prefix3}/vendor-info/query/vendorByVendorNbr9D`,
    data
  })
}
// 线上商品库导出
export const commoditylibraryExports = (data, name) => {
  return exportFile(list_url.commoditylibraryExports, data, name)
}
// 上传图片到服务器
export const uploadImages = (data) => {
  // console.log('data', data)
  return request({
    method: 'put',
    url: `${prefix1}/sys/file/upload`,
    data
  })
}
export const getDefaultPdAdders = (data) => {
  return request({
    method: 'post',
    url: `${prefix3}/mail-addr/queryMailAddrInfoByVendorNbr`,
    data
  })
}

// GBS终审 品类运营初审 维护导出接口
export const exportData = (data, name) => {
  return exportFile(url_schedule.exportComplianceAuditSkuProcess, data, name)
}
